package com.caht.servier.Impl;

import cn.hutool.json.JSONUtil;
import com.caht.DTO.inertlikestateUserDTO;
import com.caht.VO.PostsandUserVO;
import com.caht.context.BaseContext;
import com.caht.entity.likestate;
import com.caht.mapper.PostsMapper;
import com.caht.mapper.likestateMapper;
import com.caht.servier.likestateServier;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Service
@Slf4j
public class likestateServierImpl implements likestateServier {

    @Autowired
    private likestateMapper likestateMapper;
    @Autowired
    private PostsMapper postsMapper;
    /**
     * 点赞
     * @param inertlikeDTO
     */
    @Transactional
    public void clickLike(inertlikestateUserDTO inertlikeDTO) {
        Long currentId = BaseContext.getCurrentId();
        //向 帖子的 点赞中数量加 1
        postsMapper.UpdataLike(inertlikeDTO);
        //添加点赞详细
        inertlikeDTO.setUser(currentId);
        likestateMapper.inertLike(inertlikeDTO);
    }
    //取消点赞
    @Transactional
    public void cancellation(inertlikestateUserDTO inertlikeDTO) {
        Long currentId = BaseContext.getCurrentId();
        //向 帖子的 点赞中数量减 1
        postsMapper.UpdataLike(inertlikeDTO);
        //添加点赞详细
        inertlikeDTO.setUser(currentId);
        likestateMapper.cancellation(inertlikeDTO);
    }
}
